Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile Skia with Direct3D on Windows platform #2823

Merged
merged 35 commits into from
Mar 13, 2025
Merged

Conversation

Kation
Copy link
Contributor

@Kation Kation commented Apr 8, 2024

Description of Change

Compile Skia with Direct3D on Windows platform

Bugs Fixed

#2817

API Changes

None.

Behavioral Changes

None.

Required skia PR

mono/skia#121

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Merged related skia PRs
  • Changes adhere to coding standard
  • Updated documentation

@Gillibald
Copy link
Contributor

@Kation
Copy link
Contributor Author

Kation commented Apr 8, 2024

@Gillibald How to update SkiaApi.generated.cs or it should be update manually?

@mattleibow
Copy link
Contributor

I think I may have broken the merge with my merge of the Metal PR. Sorry. But, this PR is shaping up very well!

@mattleibow
Copy link
Contributor

@Gillibald How to update SkiaApi.generated.cs or it should be update manually?

I think you found the generator in the utils directory. You should be able to just run this one on a Windows machine with VS installed: https://github.com/mono/SkiaSharp/blob/main/utils/generate.ps1

@Kation
Copy link
Contributor Author

Kation commented Apr 9, 2024

@mattleibow Yeah, I found it.

Many documents are out of date or missing. I spent a lot of date to look up how to modify codes.

Pipelines failed with Unable to find package Vortice.Direct3D12 and old feature tests. How to fix it?

@mattleibow
Copy link
Contributor

ah, we have a mirror of all packages for reasons to prevent supply chain attacks. Let me mirror those packs.

Copy link
Contributor

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is green it seems. The samples are fail in some cases because the Tizen project was removed from the sln.

How much extra size is added to the binary?

@@ -63,6 +63,18 @@ public static GRContext CreateVulkan (GRVkBackendContext backendContext, GRConte
}
}

public static GRContext CreateDirect3D (GRD3dBackendcontext backendContext, GRContextOptions options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate myself so much... But this may need to be 3d with a lowercase d for consistency. So yuck to look at and I have no idea what I was thinking at the time. Sorry universe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that every Direct3D library use uppercase D, so I'm doing same with that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but sadly if you look at my OpenGl members I must have lost my mind. Everywhere it is uppercase-G-lowercase-l 😭

@Kation
Copy link
Contributor Author

Kation commented Apr 10, 2024

increase 1,773,537 bytes compare to 3.0.0-preview2.1

Copy link
Contributor

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close, I added more comments on the native PR that is more about API shape and maybe an issue with native interop: mono/skia#121 (review)

Also, it would be great to get some sort of test to make sure that at least using these new types are not crashing because of some interop issue.

@@ -63,6 +63,18 @@ public static GRContext CreateVulkan (GRVkBackendContext backendContext, GRConte
}
}

public static GRContext CreateDirect3D (GRD3dBackendcontext backendContext, GRContextOptions options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but sadly if you look at my OpenGl members I must have lost my mind. Everywhere it is uppercase-G-lowercase-l 😭

@Kation
Copy link
Contributor Author

Kation commented Apr 12, 2024

@mattleibow Why android and macos test run failed?

@mattleibow
Copy link
Contributor

@mattleibow Why android and macos test run failed?

I think there is a problem with the magic step that is supposed to use the correct build of skia. Just commit the submodule in this PR. Then the checkout of SkiaSharp will also pull the correct skia.

@mattleibow
Copy link
Contributor

For the tests, I think this will work - still installing tooling as I have a new laptop: 6cf79ea

Hopefully it just works, I copied the context setup from the skia test files... seems simple enough, no idea.

@Kation
Copy link
Contributor Author

Kation commented Apr 16, 2024

For the tests, I think this will work - still installing tooling as I have a new laptop: 6cf79ea

Hopefully it just works, I copied the context setup from the skia test files... seems simple enough, no idea.

It's fail randomly I think. Sometime android failed and sometime macos failed or android and macos both failed.

@mattleibow
Copy link
Contributor

ah, yeah sorry. Those are a bit flakey right now. Sometimes the Android emulator does not boot, or the macOS test runner crashes.

@Kation
Copy link
Contributor Author

Kation commented Apr 16, 2024

Maybe you can click Rerun failed jobs button to try for more times.

@mattleibow
Copy link
Contributor

@Kation are you able to write some tests?

@Kation
Copy link
Contributor Author

Kation commented Mar 5, 2025

@mattleibow Workflow still report unauthorized.

@mattleibow
Copy link
Contributor

Yeah, the public pool is a bit full, so I am using an internal one.

The build failed with the Nano Server checks saying there is no Direct3D available on Nano Server. I need to verify that, but for now I disabled D3D on Nano. So far, all the native builds looked green. Running again and the tests will tell us things hopefully.

@mattleibow
Copy link
Contributor

The internal pipeline finished and was all green. So, I think we should be able to merge this soon.

I will give it another review and also try get the public builds working so folks can try out the artifacts.

@jeremy-visionaid
Copy link
Contributor

I will happily be guinea pig!

@mattleibow
Copy link
Contributor

/azp run

Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@mattleibow
Copy link
Contributor

I will happily be guinea pig!

You should be able to download the nuget artifact from https://dev.azure.com/xamarin/public/_build/results?buildId=137303&view=results

@jeremy-visionaid
Copy link
Contributor

Thanks for making those artifacts available! I'm afraid I hadn't looked too closely at the state of Skia's backend support and hadn't realized that the Ganesh set of backends included DX12 and not DX11. So, I was hoping that I could just rip out ANGLE and set up Skia contexts with DX11 instead. I don't think it should be a big deal to create a DX12 device and share the required textures/resources between the two, and probably still preferable to ANGLE for my usage. However, it'll take me a bit longer to spin something up with this than what I first thought...

@jeremy-visionaid
Copy link
Contributor

OK, I've got a working proof of concept using the D3D backend. Took me a little while to check the performance. Looks about 5-10% faster than the ANGLE build for our app, and I'll get to drop a couple of dependencies once this gets merged/released. Nice work @Kation!

@mattleibow
Copy link
Contributor

mattleibow commented Mar 10, 2025

Very nice to hear! Are you able to share samples? I am no Direct-anything expert, so any samples will be great.

I am wanting to add more things to the views as well as make better samples showing different backends.

@mattleibow
Copy link
Contributor

mattleibow commented Mar 10, 2025

Hate to be that guy but have any other Direct3D C# binding libraries been considered. This Vortice.Direct3D12 seems to be a niche one. One example is Silk.NET which is under .NET Foundation umbrella (No affiliation on my side).

This is a good point. Thanks for making it here.

However, the main aim of this PR (for me) is to merge the base APIs that people can use. If you (or anyone) are familiar with Silk.NET, then feel free to open a PR or issue with some code I can add to the repo.

The way we are doing the nugets here is specifically to avoid a dependency lock-in, so the library specific code is in a separate nuget that can be deprecated/updated/changed at any time without breaking the core skia libraries. For example, to use Vortice, there will be a separate SkiaSharp.Direct3D.Vortice nuget that you would reference. There may be SkiaSharp.Direct3D.Silk.NET nuget in the future (if you open a PR 😉).

@jeremy-visionaid
Copy link
Contributor

jeremy-visionaid commented Mar 11, 2025

@mattleibow I'm not sure what value samples from my usage would add over the the unit tests that Kation added. I use different bindings, and most of the work I had to do was for D3D11/D3D12 interop, which I think is probably out of scope. D3D12 is a pretty complex beast - setting up Skia/SkiaSharp is the easy bit 😄 Suffice to say that I can create a GRContext and render to an SKSurface via GRBackendRenderTarget or GRBackendTexture just fine with this PR.

@maw136 FWIW regarding bindings, I didn't use the SkiaSharp.Direct3D.Vortice package, just the base GRD3DBackendContext/GRBackendRenderTarget/GRD3DTextureResourceInfo. Using Silk.NET, CsWin32 or any other bindings directly with them should be essentially trivial.

@mattleibow
Copy link
Contributor

/azp run

Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@mattleibow
Copy link
Contributor

OK, I think this PR is fianlly ready! Thanks for sticking with it for so long and everyone in the discussions.

Going to merge and will let everyone know when it is available on the preview feed - typically in 3 hours.

@Kation
Copy link
Contributor Author

Kation commented Mar 14, 2025

@mattleibow Pipeline still queue for running and report error, can we stop it?

@mattleibow
Copy link
Contributor

The pipeline is finished and the version is 3.119.0-preview.0.20 on the preview feed.

@mattleibow mattleibow mentioned this pull request Mar 14, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants